Skip to content

fix(graph): persistent DAG mode panics on startup (shared Sled Db)#101

Merged
ApiliumDevTeam merged 1 commit into
mainfrom
fix/dag-sled-share
Jun 22, 2026
Merged

fix(graph): persistent DAG mode panics on startup (shared Sled Db)#101
ApiliumDevTeam merged 1 commit into
mainfrom
fix/dag-sled-share

Conversation

@ApiliumDevTeam

Copy link
Copy Markdown
Contributor

Summary

aingle-cortex --db <path> (any persistent run with the dag feature, including the MCP server --mcp --db <path>) panicked on startup:

Failed to enable persistent DAG at '...graph.sled': sled open error: could not
acquire lock on "...graph.sled\db": another process has it locked

Root cause

The triple store opened the Sled DB via sled::open(path) (holding the file lock), then GraphDB::enable_dag_persistent(path) did a second sled::open(path) on the same path for the DAG backend. The two opens did not share the instance, so the second failed to acquire the lock. The DAG was meant to share the triple store's Db (one Db, a separate "dag" tree) but the implementation re-opened the path instead.

This only manifested with a real --db <path>; every test uses :memory: (no file lock), which is why it was never caught. Persistent DAG mode effectively never started.

Fix

Share the triple store's sled::Db handle (cheaply clonable — Arc inside) with the DAG backend instead of re-opening the path:

  • StorageBackend gains as_any() (downcasting support); implemented by all four backends.
  • SledBackend::db() exposes the handle; GraphStore::backend_as_any() reaches it.
  • SledDagBackend::from_db(&Db) opens the "dag" tree on an existing Db.
  • GraphDB::enable_dag_persistent (and the same latent bug in sled_with_dag) now downcast to SledBackend and open the DAG tree on the shared Db, falling back to path-open only for non-Sled backends.

Test plan

  • New regression test enable_dag_persistent_shares_sled_db_no_lockfailed before (the exact lock error), passes after.
  • cargo test -p aingle_graph --features dag — 77 passed.
  • cargo build -p aingle_cortex --features "mcp dag" and default — compile clean.
  • End-to-end: aingle-cortex --mcp --db <path> now boots (serverInfo on stdout, "DAG persistence enabled (Sled)", no panic). Verified persistence across process restart: write a triple in one process, read it back (+ signed dag_history) in a fresh process on the same DB.

Notes

  • Pre-existing bug (not a regression); surfaced while smoke-testing the MCP server's persistent config.
  • Also fixes sled_with_dag, which had the identical double-open.

enable_dag_persistent and sled_with_dag previously called sled::open on
the same path the triple store already had open, which deadlocks on the
file lock (only on real --db paths; :memory: masked it in tests).

Now the DAG tree is opened on the triple store's existing sled::Db via a
new SledDagBackend::from_db, reached through a StorageBackend::as_any
downcast to SledBackend. Adds a regression test reproducing the lock
self-conflict.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ApiliumDevTeam ApiliumDevTeam merged commit 9d659ae into main Jun 22, 2026
15 of 16 checks passed
ApiliumDevTeam added a commit that referenced this pull request Jun 23, 2026
fix(graph): persistent DAG mode panics on startup (shared Sled Db)
@ApiliumDevTeam ApiliumDevTeam deleted the fix/dag-sled-share branch June 23, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant